package com.sky.mapper;


import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {


    /**
     * 添加地址
     * @param addressBook
     */
    @Insert("insert into sky_take_out.address_book(user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label) " +
            "values (#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label})")
    void insertAddressBook(AddressBook addressBook);


    /**
     * 查询所有的地址信息
     * @return
     */
    @Select("select * from sky_take_out.address_book where user_id = #{userId}")
    List<AddressBook> selectAllAddressBook(AddressBook addressBook);


    /**
     * 查询默认地址
     * @param currentId
     * @return
     */
    @Select("select * from sky_take_out.address_book where user_id = #{userId} and is_default = 1")
    AddressBook selectIsDefault(Long currentId);


    /**
     * 通过ID查询地址信息
     * @param id
     * @return
     */
    @Select("select * from sky_take_out.address_book where id = #{id}")
    AddressBook selectById(Long id);


    /**
     * 根据ID修改地址
     * @param addressBook
     */
    void modifyAddressBook(AddressBook addressBook);


    /**
     * 根据ID删除地址
     * @param id
     */
    @Delete("delete from sky_take_out.address_book where id = #{id}")
    void deleteAddressBook(Long id);


    /**
     * 修改所有的地址为非默认地址
     * @param addressBook
     */
    @Update("update sky_take_out.address_book set is_default = #{isDefault} where user_id = #{userId}")
    void modifyAllDefault(AddressBook addressBook);
}
